package com.dogdog.activity;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.dogdog.bean.Status;
import com.dogdog.manager.C;
import com.dogdog.manager.MyApplication;
import com.dogdog.util.ToastTool;

import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.TextView;

public class PetInfoRegister extends BaseActivity{
	
	private AutoCompleteTextView ed_kind;
	private EditText ed_name;
	private EditText ed_age;
	private EditText ed_time;
    String[] kinds=new String[]{"金毛","牧羊犬","杜宾","大型泰迪","拉布拉多","哈士奇","柴犬",
    		"松狮","萨摩耶","腊肠犬","喜乐蒂","吉娃娃","博美","西施","巴哥",
    		"迷你杜宾","京巴","梗类","约克夏","柯基犬","比熊 ","蝴蝶犬"};
    	//拉布拉多之前是大型犬（包含拉布拉多），哈士奇~喜乐蒂（中型犬），泰迪~蝴蝶犬（小型）	
	
	public void onCreate(android.os.Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.petinfo_edit);
		initView();
	}
	
	public void initView(){
		ed_kind=(AutoCompleteTextView)findViewById(R.id.ed_kind);
		ed_kind.setAdapter(new ArrayAdapter<String>(PetInfoRegister.this,
				android.R.layout.simple_list_item_1,kinds));
		ed_age=(EditText)findViewById(R.id.ed_age);
		ed_name=(EditText)findViewById(R.id.ed_name);
		ed_time=(EditText)findViewById(R.id.ed_time);
		((TextView)findViewById(R.id.tv_title)).setText("注册宠物信息");
	}
	
	public void petRegisterRequest(View v){
		StringRequest petRegister =new StringRequest(
				Method.POST,
				C.URL.PETREGISTER,
				new Response.Listener<String>(){
				@Override
				public void onResponse(String response) {
				Status statu=gson().fromJson(response.toString(),Status.class);
				if(statu.getState()==1){
					finish();
				}else{
					ToastTool.status(PetInfoRegister.this,statu);
				}  
					}; 
				},
				new Response.ErrorListener(){
				@Override
				public void onErrorResponse(VolleyError error) {
				ToastTool.show(PetInfoRegister.this,"注册宠物信息失败");		
					};
				}){
			   protected java.util.Map<String,String> getParams() 
					   throws AuthFailureError {
				   Map<String,String> param=new HashMap<String,String>();
				   param.put("pet_name",ed_name.getText().toString());
				   param.put("pet_age",ed_age.getText().toString());
				   param.put("pet_kind",ed_kind.getText().toString());
				   param.put("pet_time",ed_time.getText().toString());
				   return param;
			   };
		};
		MyApplication.getHttpQueue().add(petRegister);
	}
	
}
